package cc.fs.zhihuapp.utils;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import rx.Observable;
import rx.subjects.BehaviorSubject;

/**
 * Created by fostion on 2015/9/6.
 */
public class Events {

    public Observable<String> text(EditText editText){
        final BehaviorSubject<String> behaviourSubject = BehaviorSubject.create(editText.getText().toString());
        editText.addTextChangedListener(new TextWatcher(){

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                behaviourSubject.onNext(s.toString());
            }
        });
        return behaviourSubject;
    }

}
